// Package startup
// Created by GoLand
// @User: lenora
// @Date: 2024/8/27
// @Time: 14:53

package startup

import (
	"camp/microbook/interactive/repository/dao"
	micrologger "camp/microbook/pkg/logger"
	"github.com/redis/go-redis/v9"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

func InitRedis() redis.Cmdable {
	return redis.NewClient(&redis.Options{
		Addr: "localhost:6378",
	})
}

func InitDb() *gorm.DB {
	db, err := gorm.Open(
		mysql.Open("root:root@tcp(localhost:3306)/camp"),
		&gorm.Config{
			Logger: logger.Default.LogMode(logger.Info),
		},
	)
	if err != nil {
		panic(err)
	}

	if err := dao.InitTables(db); err != nil {
		panic(err)
	}

	return db
}

func InitLogger() micrologger.Logger {
	return micrologger.NewNoOpLogger()
}
